<%#
 Copyright 2013-2025 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      https://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
<div>
  <h2>
    <span id="user-management-page-heading" data-cy="userManagementPageHeading">__jhiTranslateTag__('userManagement.home.title')</span>

    <div class="d-flex justify-content-end">
      <button class="btn btn-info me-2" (click)="loadAll()" [disabled]="isLoading()">
        <fa-icon icon="sync" [animation]="isLoading() ? 'spin' : undefined" />
        <span>__jhiTranslateTag__('userManagement.home.refreshListLabel')</span>
      </button>
      <button class="btn btn-primary jh-create-entity" [routerLink]="['./new']">
        <fa-icon icon="plus" /> <span>__jhiTranslateTag__('userManagement.home.createLabel')</span>
      </button>
    </div>
  </h2>

  <<%= jhiPrefixDashed %>-alert-error />

  <<%= jhiPrefixDashed %>-alert />

@if (users()) {
  <div class="table-responsive">
    <table class="table table-striped" aria-describedby="user-management-page-heading">
      <thead>
        <tr<% if (!databaseTypeCassandra) { %> <%= jhiPrefix %>Sort [(sortState)]="sortState" (sortChange)="transition($event)"<% } %>>
          <th scope="col"<% if (!databaseTypeCassandra) { %> <%= jhiPrefix %>SortBy="id"<% } %>>
            <span>__jhiTranslateTag__('global.field.id')</span><% if (databaseType !== 'cassandra') { %> <fa-icon icon="sort" /><% } %>
          </th>
          <th scope="col"<% if (!databaseTypeCassandra) { %> <%= jhiPrefix %>SortBy="login"<% } %>>
            <span>__jhiTranslateTag__('userManagement.login')</span><% if (databaseType !== 'cassandra') { %> <fa-icon icon="sort" /><% } %>
          </th>
          <th scope="col"<% if (!databaseTypeCassandra) { %> <%= jhiPrefix %>SortBy="email"<% } %>>
            <span>__jhiTranslateTag__('userManagement.email')</span><% if (databaseType !== 'cassandra') { %> <fa-icon icon="sort" /><% } %>
          </th>
          <th scope="col"></th>
<%_ if (enableTranslation) { _%>
          <th scope="col"<% if (!databaseTypeCassandra) { %> <%= jhiPrefix %>SortBy="langKey"<% } %>>
            <span>__jhiTranslateTag__('userManagement.langKey')</span><% if (databaseType !== 'cassandra') { %> <fa-icon icon="sort" /><% } %>
          </th>
<%_ } _%>
          <th scope="col"><span>__jhiTranslateTag__('userManagement.profiles')</span></th>
<%_ if (!databaseTypeCassandra) { _%>
          <th scope="col" <%= jhiPrefix %>SortBy="createdDate">
            <span>__jhiTranslateTag__('userManagement.createdDate')</span> <fa-icon icon="sort" />
          </th>
          <th scope="col" <%= jhiPrefix %>SortBy="lastModifiedBy">
            <span>__jhiTranslateTag__('userManagement.lastModifiedBy')</span> <fa-icon icon="sort" />
          </th>
          <th scope="col" <%= jhiPrefix %>SortBy="lastModifiedDate">
            <span>__jhiTranslateTag__('userManagement.lastModifiedDate')</span> <fa-icon icon="sort" />
          </th>
<%_ } _%>
          <th scope="col"></th>
        </tr>
      </thead>
      <tbody>
      @for (user of users(); track trackIdentity(user)) {
        <tr>
          <td>
            <a [routerLink]="['./', user.login, 'view']">{{ user.id }}</a>
          </td>
          <td>{{ user.login }}</td>
          <td>{{ user.email }}</td>
          <td>
          @if (!user.activated) {
            <button class="btn btn-danger btn-sm"
              (click)="setActive(user, true)"
            >__jhiTranslateTag__('userManagement.deactivated')</button>
          } @else {
            <button class="btn btn-success btn-sm"
              (click)="setActive(user, false)"
              [disabled]="!currentAccount() || currentAccount()?.login === user.login"
            >__jhiTranslateTag__('userManagement.activated')</button>
          }
          </td>
<%_ if (enableTranslation) { _%>
          <td>{{ user.langKey }}</td>
<%_ } _%>
          <td>
          @for (authority of user.authorities; track $index) {
            <div>
              <span class="badge bg-info">{{ authority }}</span>
            </div>
          }
          </td>
<%_ if (!databaseTypeCassandra) { _%>
          <td>{{ user.createdDate | date: 'dd/MM/yy HH:mm' }}</td>
          <td>{{ user.lastModifiedBy }}</td>
          <td>{{ user.lastModifiedDate | date: 'dd/MM/yy HH:mm' }}</td>
<%_ } _%>
          <td class="text-end">
            <div class="btn-group">
              <button type="submit" [routerLink]="['./', user.login, 'view']" class="btn btn-info btn-sm">
                <fa-icon icon="eye" />
                <span class="d-none d-md-inline">__jhiTranslateTag__('entity.action.view')</span>
              </button>

              <button type="submit" [routerLink]="['./', user.login, 'edit']" queryParamsHandling="merge" class="btn btn-primary btn-sm">
                <fa-icon icon="pencil-alt" />
                <span class="d-none d-md-inline">__jhiTranslateTag__('entity.action.edit')</span>
              </button>

              <button
                type="button"
                (click)="deleteUser(user)"
                class="btn btn-danger btn-sm"
                [disabled]="!currentAccount() || currentAccount()?.login === user.login"
              >
                <fa-icon icon="times" />
                <span class="d-none d-md-inline">__jhiTranslateTag__('entity.action.delete')</span>
              </button>
            </div>
          </td>
        </tr>
      }
      </tbody>
    </table>
  </div>
<%_ if (!databaseTypeCassandra) { _%>

  <div>
    <div class="d-flex justify-content-center">
      <<%= jhiPrefixDashed %>-item-count [params]="{ page, totalItems: totalItems(), itemsPerPage }" />
    </div>

    <div class="d-flex justify-content-center">
      <ngb-pagination
        [collectionSize]="totalItems()"
        [(page)]="page"
        [pageSize]="itemsPerPage"
        [maxSize]="5"
        [rotate]="true"
        [boundaryLinks]="true"
        (pageChange)="transition()"
      />
    </div>
  </div>
<%_ } _%>
}
</div>
